package com.mall.server.controller;

import com.mall.autoconfig.template.OssTemplate;
import com.mall.commons.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;

@CrossOrigin
@RestController
@RequestMapping("/aliyun")
public class AliyunController {
    @Autowired
    private OssTemplate ossTemplate;

    /**
     * 文件上传
     * @param photoFile
     * @return
     */
    @PostMapping("/oss/upload")
    public R upload(MultipartFile photoFile) throws IOException {
            String url = ossTemplate.upload(photoFile.getOriginalFilename(), photoFile.getInputStream());
            HashMap<String, String> map = new HashMap<>();
            map.put("url",url);
            return R.success(map);
    }


}
